package com.epoint.mobileoa.adapter;

import java.util.List;
import java.util.Map;

import com.epoint.mobileoa.bizlogic.Res;
import com.epoint.mobileoa.tools.PropertiesHelp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


/**
 * @author liyc
 * @time 2012-2-4 上午10:27:21
 * @annotation 通知公告列表适配器
 */
public class NoticeListAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	List<Map<String, Object>> mData;
	private Context con;
	public NoticeListAdapter(Context context, List<Map<String, Object>> mData) {
		this.mData = mData;
		this.mInflater = LayoutInflater.from(context);
		this.con = context;
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(Res.getLayoutInt("noticelist"), null);
			holder.ml_mailimg = (ImageView) convertView
					.findViewById(Res.getIdInt("noticelist_img"));
			holder.ml_attach = (ImageView) convertView
					.findViewById(Res.getIdInt("noticelist_attach"));
			holder.ml_mailtitle = (TextView) convertView
					.findViewById(Res.getIdInt("noticelist_title"));
			holder.ml_sandt = (TextView) convertView
					.findViewById(Res.getIdInt("noticelist_send"));
			holder.notice_time = (TextView) convertView
					.findViewById(Res.getIdInt("noticelist_time"));

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if(PropertiesHelp.getProperty(con, "showNoticeListLeftImg").equals("1")){
			holder.ml_mailimg.setBackgroundResource((Integer) mData.get(position)
					.get("img"));
		}
		else{
			holder.ml_mailimg.setVisibility(View.GONE);
		}
		if (mData.get(position).containsKey("attachimg")) {
			holder.ml_attach.setBackgroundResource((Integer) mData
					.get(position).get("attachimg"));
		}

		holder.ml_mailtitle.setText((String) mData.get(position).get(
				"title"));
		String sender = (String) mData.get(position).get("sender");
		String time = (String) mData.get(position).get("time");
//		Spanned h = Html.fromHtml("<font color='#00FFCC'>" + sender
//				+ "</font>&nbsp;&nbsp;" + "<font color=yellow>" + time
//				+ "</font>");
		holder.ml_sandt.setText(sender);
		holder.notice_time.setText(time);
		return convertView;
	}

	public class ViewHolder {
		public ImageView ml_mailimg;
		public ImageView ml_attach;
		public TextView ml_mailtitle;
		public TextView ml_sandt;
		public TextView notice_time;
	}
}